#ifndef _SRC_NET_ACCEPTOR_CC_
#define _SRC_NET_ACCEPTOR_CC_

#include <functional>

#include "src/base/utils.h"
#include "src/net/channel.h"
#include "src/net/socket.h"

namespace fio66::net {
class EventLoop;
class InetAddress;

class Acceptor {
 public:
  DISALLOW_COPY_AND_ASSIGN(Acceptor)

  typedef std::function<void(int sockfd, const InetAddress&)>
      NewConnectionCallback;

  Acceptor(EventLoop* loop, const InetAddress& listenAddr, bool reuseport);
  ~Acceptor();

  void SetNewConnectionCallback(const NewConnectionCallback& cb) {
    new_connection_callback_ = cb;
  }

  void Listen();

  bool Listening() const { return listening_; }

  // Deprecated, use the correct spelling one above.
  // Leave the wrong spelling here in case one needs to grep it for error
  // messages. bool listenning() const { return listening(); }

 private:
  void HandleRead();

  EventLoop* loop_;
  Socket accept_socket_;
  Channel accept_channel_;
  NewConnectionCallback new_connection_callback_;
  bool listening_;
  int idle_fd_;
};
}  // namespace fio66::net

#endif  // _SRC_NET_ACCEPTOR_CC_
